<template>
  <div class="invitation-box">
    <Form :model="invitationForm" :rules="invitationFormFules" :disabled="isOrder" ref="invitationFormRef"
      label-position="top">
      <!-- 客资跟踪 -->
      <Card class="box-card" :shadow="true" v-if="!isOrder">
        <p slot="title" class="cardp">
          <Icon type="md-list"></Icon>
          <span>客资跟踪</span>
        </p>
        <Row :gutter="16">
          <Col span="6">
          <FormItem label="跟踪类型" prop="trackingData.tracking_type">
            <Select v-model="invitationForm.trackingData.tracking_type" clearable placeholder="跟踪类型">
              <Option v-for="item in tracking_type_options" :value="item.value" :key="item.value">{{ item.label }}
              </Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="下次跟踪时间">
            <DatePicker clearable format="yyyy-MM-dd" :options="disableOptions" :value="invitationForm.trackingData.next_tracking_time"
              @on-change="next_tracking_time_change" type="date" placeholder="下次跟踪时间"></DatePicker>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="意向度">
            <Select v-model="invitationForm.trackingData.intention_level" clearable placeholder="预算">
              <Option value="A (3-6个月)">A (3-6个月)</Option>
              <Option value="B (一年内)">B (一年内)</Option>
              <Option value="C (两年内)">C (两年内)</Option>
              <Option value="D (潜在客户)">D (潜在客户)</Option>
              <Option value="E">E</Option>
              <Option value="F">F</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="预算">
            <Select v-model="invitationForm.trackingData.budget" clearable placeholder="预算">
              <Option v-for="item in budget_options" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="图片备注" prop="imgRemark">
            <el-upload action="11" :http-request="kzRemarksUpload" :limit="1" :file-list="attach_list"
              list-type="picture-card" compress="false" :on-exceed="handlePictureCardExceed"
              :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
              <i class="el-icon-camera"></i>
            </el-upload>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="跟踪备注">
            <Input v-model="invitationForm.trackingData.tracking_note" type="textarea" :rows="1"
              placeholder="跟踪备注"></Input>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="">
            <Button type="primary" icon="ios-checkmark-circle" @click="trackingConfirm">跟踪确定</Button>
          </FormItem>
          </Col>
        </Row>
      </Card>
      <!-- 预约到店 -->
      <Card class="box-card" :shadow="true" v-if="!isOrder">
        <p slot="title" class="cardp">
          <Icon type="md-list"></Icon>
          <span>预约到店</span>
        </p>
        <Row :gutter="16">
          <Col span="6">
          <FormItem label="选择门店" prop="appointmentData.store_id">
            <Select v-model="invitationForm.appointmentData.store_id" clearable placeholder="跟踪类型">
              <Option v-for="item in storeList" :value="item.store_id" :key="item.store_id">{{ item.store_name }}
              </Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="预约到店日期" prop="appointmentData.appointment_date">
            <DatePicker clearable :options="disableOptions" format="yyyy-MM-dd"  @on-change="appointment_date_change" v-model="invitationForm.appointmentData.appointment_date" type="date"
              placeholder="预约到店日期"></DatePicker>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="预约到店时间" prop="appointmentData.appointment_time">
            <Select v-model="invitationForm.appointmentData.appointment_time" clearable placeholder="预约到店时间">
              <Option v-for="item in appointment_time_options" :label="item.label" :value="item.value"
                :key="item.value">
                <span>{{ item.label }}</span>
                <span style="color: rgb(153, 153, 153);">{{ item.sublabel }}</span>
              </Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="12">
          <FormItem label="预约备注" prop="appointmentData.appointment_note">
            <Input v-model="invitationForm.appointmentData.appointment_note" type="textarea" :rows="1"
              placeholder="预约备注"></Input>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="">
            <Button type="primary" icon="ios-checkmark-circle" @click="appointmentConfirm">预约确定</Button>
          </FormItem>
          </Col>
        </Row>
      </Card>
      <!-- 邀约订单 -->
      <Card class="box-card" :shadow="true">
        <p slot="title" class="cardp">
          <Icon type="md-list"></Icon>
          <span>邀约订单</span>
        </p>
        <Row :gutter="16">
          <!-- <Col span="6">
            <FormItem label="选择分店">
              <Select v-model="invitationForm.branch_store_name" clearable placeholder="选择分店">
                <Option v-for="item in branch_store_options" :value="item.branch_store_id" :key="item.branch_store_id">{{ item.branch_store_name }}</Option>
              </Select>
            </FormItem>
          </Col> -->
          <Col span="6">
          <FormItem label="订单类型" prop="orderData.order_type">
            <Select v-model="invitationForm.orderData.order_type" clearable placeholder="订单类型">
              <Option v-for="item in order_type_options" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="订单时间">
            <DatePicker clearable v-model="invitationForm.orderData.order_time" @on-change="order_time_change"
              type="datetime" format="yyyy-MM-dd HH:mm" placeholder="下单时间"></DatePicker>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="门店员工">
            <Cascader :value="storeYG" :data="storeEmployeeOptions" @on-change="storeEmployeeChange"></Cascader>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="订单金额">
            <Input v-model="invitationForm.orderData.order_amount" icon="logo-yen" type="number"
              placeholder="订单金额"></Input>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="已收金额">
            <Input v-model="invitationForm.orderData.received_amount" icon="logo-yen" type="number"
              placeholder="已收金额"></Input>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="订金">
            <Input v-model="invitationForm.orderData.deposit" icon="logo-yen" type="number" placeholder="订金"></Input>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="婚期">
            <DatePicker clearable format="yyyy-MM-dd" :value="invitationForm.orderData.wedding_date" :options="disableOptions"
              @on-change="wedding_date_change" type="date" placeholder="婚期"></DatePicker>
          </FormItem>
          </Col>
          <Col span="12">
          <FormItem label="订单备注">
            <Input v-model="invitationForm.orderData.order_note" type="textarea" :rows="1" placeholder="订单备注"></Input>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="">
            <Button type="primary" icon="ios-checkmark-circle" @click="orderConfirm">邀约订单确定</Button>
          </FormItem>
          </Col>
          <!-- <Col span="6">
            <FormItem label="订单类型（ERP）">
              <Select v-model="invitationForm.order_type_ERP" clearable placeholder="订单类型（ERP）">
                <Option v-for="item in order_type_ERP_options" :value="item.value" :key="item.value">{{ item.label }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="消费类型">
              <Select v-model="invitationForm.consume_type" clearable placeholder="消费类型">
                <Option value="正常">正常</Option>
                <Option value="续订">续订</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="选择接单点">
              <Cascader :data="receive_order_addr_options" v-model="invitationForm.receive_order_addr"></Cascader>
            </FormItem>
          </Col>-->
        </Row>
        <!-- <Row :gutter="16">
          <Col span="6">
            <FormItem label="关联摄影师">
              <Select v-model="invitationForm.photographer" clearable placeholder="关联摄影师">
                <Option v-for="item in photographer_options" :value="item.value" :key="item.value">{{ item.label }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="关联化妆师">
              <Select v-model="invitationForm.makeup_artist" clearable placeholder="关联化妆师">
                <Option v-for="item in makeup_artist_options" :value="item.value" :key="item.value">{{ item.label }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="关联引导师">
              <Select v-model="invitationForm.mentor" clearable placeholder="关联引导师">
                <Option v-for="item in mentor_options" :value="item.value" :key="item.value">{{ item.label }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col span="24">
            <Card class="box-card" :bordered="false" :dis-hover="true">
              <p slot="title" class="cardp" style="font-size: 12px;">
                <Icon type="logo-dropbox"></Icon>
                <span>套餐信息</span>
              </p>
              <div slot="extra" style="font-size: 12px;">
                <ButtonGroup size="small">
                  <Tooltip content="新增省级套系">
                    <Button size="small" icon="md-add"></Button>
                  </Tooltip>
                  <Tooltip content="减少省级套系" disabled>
                    <Button size="small" disabled icon="md-remove"></Button>
                  </Tooltip>
                </ButtonGroup>
              </div>
            </Card>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col span="14">
            <FormItem label="选择套餐">
              <Select v-model="invitationForm.set_meal" clearable placeholder="选择套餐">
                <Option v-for="item in set_meal_options" :label="item.label" :value="item.value" :key="item.value">
                  <span>{{ item.label }}</span>
                  <span style="color: rgb(153, 153, 153);">{{ item.sublabel }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>-->
      </Card>
      <!-- 无效流失 -->
      <Card class="box-card" :shadow="true" v-if="!isOrder">
        <p slot="title" class="cardp">
          <Icon type="md-list"></Icon>
          <span>无效流失</span>
        </p>
        <Row :gutter="16">
          <Col span="6">
          <FormItem label="无效类型">
            <Select v-model="invitationForm.invalidData.invalid_type" clearable placeholder="无效类型">
              <Option value="无效客资">无效客资</Option>
              <Option value="流失客资">流失客资</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="无效流失原因" prop="invalidData.invalid_reason">
            <Select v-model="invitationForm.invalidData.invalid_reason" clearable placeholder="无效流失原因">
              <Option value="无法联系">无法联系</Option>
              <Option value="直接拒绝">直接拒绝</Option>
              <Option value="已在集团店订单">已在集团店订单</Option>
              <Option value="微信不存在，电话空号">微信不存在，电话空号</Option>
              <Option value="无意向">无意向</Option>
              <Option value="外地客人">外地客人</Option>
              <Option value="门店客资">门店客资</Option>
              <Option value="重复客资（爱人已了解）">重复客资（爱人已了解）</Option>
            </Select>
          </FormItem>
          </Col>
          <Col span="12">
          <FormItem label="无效备注">
            <Input v-model="invitationForm.invalidData.invalid_note" type="textarea" :rows="1"
              placeholder="无效备注"></Input>
          </FormItem>
          </Col>
          <Col span="12">
          <FormItem label="图片备注">
            <el-upload action="11" :http-request="kzRemarksUpload" :limit="1" :file-list="attach_list"
              list-type="picture-card" compress="false" :on-exceed="handlePictureCardExceed"
              :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
              <i class="el-icon-camera"></i>
            </el-upload>
          </FormItem>
          </Col>
          <Col span="6">
          <FormItem label="">
            <Button type="primary" icon="ios-checkmark-circle" style="margin-top: 50px;"
              @click="invalidConfirm">无效流失确定</Button>
          </FormItem>
          </Col>
        </Row>
      </Card>
    </Form>
    <el-dialog top="2vh" :append-to-body="true" z-index="2000" custom-class="preview-dialog" title="图片预览"
      :visible.sync="imgDialogVisible2" width="80%">
      <img class="imagePreview" :src="rowData.image_note" alt="">
    </el-dialog>
  </div>
</template>

<script>
  import {
    getAllstore,
    getAllType,
    addNewOrder
  } from "@/api/order/index";
  import {
    updateKz,
    upload_image
  } from "@/api/kz/index";
  import {
    store_employee_options
  } from './options.js'
  export default {
    data() {
      return {
        rowData: {},
        imgDialogVisible2: false,
        defaultList: [],
        attach_list: [],
        isOrder: false,
        disableOptions: {
          disabledDate (date) {
            return date && date.valueOf() < Date.now() - 86400000;
          }
        },
        invitationForm: {
          trackingData: {
            tracking_type: '', // 跟踪类型
            next_tracking_time: '', // 下次跟踪时间
            intention_level: '', // 下次跟踪时间
            budget: '', // 预算
            tracking_note: '', // 跟踪备注
          },
          tracking_employees: '', // 跟踪员工
          imgRemark: '', // 图片备注
          appointmentData: {
            store_id: '', // 门店id
            store_name: '', // 门店
            appointment_date: '', // 预约到店日期
            appointment_time: '', // 预约到店时间
            appointment_note: '', // 预约备注
          },
          orderData: {
            order_type: '邀约订单', // 订单类型
            order_time: '', // 订单时间
            store_employee: '', // 门店员工
            order_amount: '', // 订单金额
            received_amount: '', // 已收金额
            deposit: '', // 订金
            wedding_date: '', // 婚期
            order_note: '', // 订单备注
          },
          invalidData: {
            invalid_type: '', // 无效类型
            invalid_reason: '', // 无效原因
            invalid_note: '', // 无效备注
          },
          branch_store_id: '', // 分店ID
          branch_store_name: '樱桃上海', // 分店名称
          order_type_ERP: '套餐', // 分店名称
          consume_type: '正常', // 消费类型
          receive_order_addr: ['门店', '总店B'], // 消费类型
          photographer: '', // 摄影师
          makeup_artist: '', // 化妆师
          mentor: '', // 引导师
          set_meal: '', // 套餐
        },
        invitationFormFules: {
          'trackingData.tracking_type': [{
            required: true,
            message: '跟踪类型必填'
          }],
          'appointmentData.store_id': [{
            required: true,
            message: '预约门店必填'
          }],
          'appointmentData.appointment_date': [{
            required: true,
            message: '预约到店日期必填'
          }],
          'appointmentData.appointment_time': [{
            required: true,
            message: '预约到店时间必填'
          }],
          'orderData.order_type': [{
            required: true,
            message: '订单类型必填'
          }],
          'invalidData.invalid_reason': [{
            required: true,
            message: '无效流失原因必填'
          }],
        },
        storeEmployeeOptions: [],
        storeYG: [],
        tracking_type_options: [{
            label: '1日再跟踪',
            value: '5'
          },
          {
            label: '2日再跟踪',
            value: '6'
          },
          {
            label: '3日再跟踪',
            value: '7'
          },
          {
            label: '1周再跟踪',
            value: '8'
          },
          {
            label: '2周再跟踪',
            value: '9'
          },
          {
            label: '1月再跟踪',
            value: '10'
          },
          {
            label: '2月再跟踪',
            value: '11'
          },
          /* {label:'半年内再跟踪',value:'半年内再跟踪'},
          {label:'重复客资',value:'重复客资'},
          {label:'未联系上',value:'未联系上'},
          {label:'进店保留',value:'进店保留'},
          {label:'百天一次跟踪',value:'百天一次跟踪'},
          {label:'已定别家待跟踪',value:'已定别家待跟踪'},
          {label:'跟踪中',value:'跟踪中'},
          {label:'约拍',value:'约拍'},
          {label:'一年后再跟踪',value:'一年后再跟踪'},
          {label:'猫猫测试',value:'猫猫测试'},
          {label:'12小时内再跟进',value:'12小时内再跟进'},
          {label:'24小时内再跟进',value:'24小时内再跟进'},
          {label:'72小时内再跟进',value:'72小时内再跟进'},
          {label:'无效待审批',value:'无效待审批'},
          {label:'长期跟进',value:'长期跟进'}, */
        ],
        budget_options: [{
            label: '2k以下',
            value: '2k以下'
          },
          {
            label: '4k',
            value: '4k'
          },
          {
            label: '6k',
            value: '6k'
          },
          {
            label: '6k-8k',
            value: '6k-8k'
          },
          {
            label: '8k-10k',
            value: '8k-10k'
          },
          {
            label: '10k以上',
            value: '10k以上'
          },
          {
            label: '其他',
            value: '其他'
          }
        ],
        storeList: [], // 门店列表
        appointment_time_options: [{
            label: '7:00',
            sublabel: '（已预约 0 人）',
            value: '7:00'
          },
          {
            label: '7:30',
            sublabel: '（已预约 0 人）',
            value: '7:30'
          },
          {
            label: '8:00',
            sublabel: '（已预约 0 人）',
            value: '8:00'
          },
          {
            label: '8:30',
            sublabel: '（已预约 0 人）',
            value: '8:30'
          },
          {
            label: '9:00',
            sublabel: '（已预约 0 人）',
            value: '9:00'
          },
          {
            label: '9:30',
            sublabel: '（已预约 0 人）',
            value: '9:30'
          },
          {
            label: '10:00',
            sublabel: '（已预约 0 人）',
            value: '10:00'
          },
          {
            label: '10:30',
            sublabel: '（已预约 0 人）',
            value: '10:30'
          },
          {
            label: '11:00',
            sublabel: '（已预约 0 人）',
            value: '11:00'
          },
          {
            label: '11:30',
            sublabel: '（已预约 0 人）',
            value: '11:30'
          },
          {
            label: '12:00',
            sublabel: '（已预约 0 人）',
            value: '12:00'
          },
          {
            label: '12:30',
            sublabel: '（已预约 0 人）',
            value: '12:30'
          },
          {
            label: '13:00',
            sublabel: '（已预约 0 人）',
            value: '13:00'
          },
          {
            label: '13:30',
            sublabel: '（已预约 0 人）',
            value: '13:30'
          },
          {
            label: '14:00',
            sublabel: '（已预约 0 人）',
            value: '14:00'
          },
          {
            label: '14:30',
            sublabel: '（已预约 0 人）',
            value: '14:30'
          },
          {
            label: '15:00',
            sublabel: '（已预约 0 人）',
            value: '15:00'
          },
          {
            label: '15:30',
            sublabel: '（已预约 0 人）',
            value: '15:30'
          },
          {
            label: '16:00',
            sublabel: '（已预约 0 人）',
            value: '16:00'
          },
          {
            label: '16:30',
            sublabel: '（已预约 0 人）',
            value: '16:30'
          },
          {
            label: '17:00',
            sublabel: '（已预约 0 人）',
            value: '17:00'
          },
          {
            label: '17:30',
            sublabel: '（已预约 0 人）',
            value: '17:30'
          },
          {
            label: '18:00',
            sublabel: '（已预约 0 人）',
            value: '18:00'
          },
          {
            label: '18:30',
            sublabel: '（已预约 0 人）',
            value: '18:30'
          },
          {
            label: '19:00',
            sublabel: '（已预约 0 人）',
            value: '19:00'
          },
          {
            label: '19:30',
            sublabel: '（已预约 0 人）',
            value: '19:30'
          },
          {
            label: '20:00',
            sublabel: '（已预约 0 人）',
            value: '20:00'
          },
          {
            label: '20:30',
            sublabel: '（已预约 0 人）',
            value: '20:30'
          },
          {
            label: '21:00',
            sublabel: '（已预约 0 人）',
            value: '21:00'
          },
          {
            label: '21:30',
            sublabel: '（已预约 0 人）',
            value: '21:30'
          },
        ],
        branch_store_options: [{
            branch_store_name: '樱桃上海',
            branch_store_id: '樱桃上海'
          },
          {
            branch_store_name: '樱桃武汉',
            branch_store_id: '樱桃武汉'
          },
          {
            branch_store_name: '樱桃成都',
            branch_store_id: '樱桃成都'
          },
          {
            branch_store_name: '樱桃三亚店',
            branch_store_id: '樱桃三亚店'
          },
          {
            branch_store_name: '樱桃厦门店',
            branch_store_id: '樱桃厦门店'
          },
          {
            branch_store_name: '樱桃写真',
            branch_store_id: '樱桃写真'
          },
          {
            branch_store_name: '樱桃-儿童',
            branch_store_id: '樱桃-儿童'
          },
          {
            branch_store_name: '樱桃全家福',
            branch_store_id: '樱桃全家福'
          },
          {
            branch_store_name: '樱桃礼服',
            branch_store_id: '樱桃礼服'
          },
          {
            branch_store_name: '樱桃儿童',
            branch_store_id: '樱桃儿童'
          },
          {
            branch_store_name: '自动化测试',
            branch_store_id: '自动化测试'
          },
        ],
        order_type_options: [{
            label: '邀约订单',
            value: '邀约订单'
          },
          {
            label: '到店订单',
            value: '到店订单'
          },
          {
            label: '礼服订单',
            value: '礼服订单'
          },
          {
            label: '跟妆订单',
            value: '跟妆订单'
          },
          {
            label: '邀约后期订单',
            value: '邀约后期订单'
          },
          {
            label: '回头订单',
            value: '回头订单'
          },
          {
            label: '在线订单',
            value: '在线订单'
          },
        ],
        order_type_ERP_options: [{
            label: '订单CZ',
            value: '订单CZ'
          },
          {
            label: '退单',
            value: '退单'
          },
          {
            label: '上门',
            value: '上门'
          },
          {
            label: '邀约订单',
            value: '邀约订单'
          },
          {
            label: '已订单',
            value: '已订单'
          },
          {
            label: '早妆',
            value: '早妆'
          },
          {
            label: '正常',
            value: '正常'
          },
          {
            label: '加急',
            value: '加急'
          },
          {
            label: '特急',
            value: '特急'
          },
          {
            label: '重拍',
            value: '重拍'
          },
          {
            label: '补拍',
            value: '补拍'
          },
          {
            label: '套餐',
            value: '套餐'
          },
          {
            label: '转单',
            value: '转单'
          },
          {
            label: '帮拍',
            value: '帮拍'
          },
          {
            label: '员工',
            value: '员工'
          }
        ],
        receive_order_addr_options: [{
            label: '门店',
            value: '门店',
            children: [{
                value: '总店B',
                label: '总店B',
              },
              {
                value: '上饶店-接单点',
                label: '上饶店-接单点',
              },
              {
                value: '基地',
                label: '基地',
              },
              {
                value: '泉城店',
                label: '泉城店',
              },
              {
                value: '测试接单点',
                label: '测试接单点',
              },
              {
                value: '旅拍',
                label: '旅拍',
              },
              {
                value: '大理基地',
                label: '大理基地',
              },
              {
                value: '瓜皮',
                label: '瓜皮',
              },
              {
                value: '一楼',
                label: '一楼',
              },
              {
                value: '二楼',
                label: '二楼',
              },
              {
                value: '接单',
                label: '接单',
              },
              {
                value: '上海店',
                label: '上海店',
              },
              {
                value: '销售A组',
                label: '销售A组',
              },
              {
                value: '巴黎婚纱',
                label: '巴黎婚纱',
              },
              {
                value: '儿童品牌',
                label: '儿童品牌',
              },
            ]
          },
          {
            label: '电商',
            value: '电商',
            children: [{
              value: '电商',
              label: '电商',
            }, ]
          },
        ],
        photographer_options: [{
            label: '单流程',
            value: '单流程'
          },
          {
            label: '摄影师1',
            value: '摄影师1'
          },
          {
            label: '摄影师',
            value: '摄影师'
          },
          {
            label: '摄影师演示账号',
            value: '摄影师演示账号'
          },
          {
            label: '张笑寒',
            value: '张笑寒'
          },
          {
            label: '曹',
            value: '曹'
          },
          {
            label: '阿涛',
            value: '阿涛'
          },
          {
            label: '黎叔',
            value: '黎叔'
          },
          {
            label: '刘和6617',
            value: '刘和6617'
          },
        ],
        makeup_artist_options: [{
            label: 'zephan',
            value: 'zephan'
          },
          {
            label: '印花',
            value: '印花'
          },
          {
            label: '化妆',
            value: '化妆'
          },
          {
            label: '化妆测试',
            value: '化妆测试'
          },
          {
            label: '画画',
            value: '画画'
          },
          {
            label: '怪兽',
            value: '怪兽'
          },
          {
            label: '黎叔',
            value: '黎叔'
          },
          {
            label: '金启明',
            value: '金启明'
          },
        ],
        mentor_options: [{
            label: '小黄',
            value: '小黄'
          },
          {
            label: '偏偏',
            value: '偏偏'
          },
          {
            label: '朱文静',
            value: '朱文静'
          },
          {
            label: '刘文龙',
            value: '刘文龙'
          },
          {
            label: '杨明欣',
            value: '杨明欣'
          },
          {
            label: '张瑞洁',
            value: '张瑞洁'
          },
          {
            label: '怪兽',
            value: '怪兽'
          },
        ],
        set_meal_options: [{
            label: '暑期体验套餐',
            sublabel: '（价格：99.00 套系：1）',
            value: '暑期体验套餐'
          },
          {
            label: '5999',
            sublabel: '（价格：6000.00 套系：2）',
            value: '5999'
          },
          {
            label: '暑期超值成长',
            sublabel: '（价格：1000.00 套系：2）',
            value: '暑期超值成长'
          },
          {
            label: '成长套餐',
            sublabel: '（价格：1000.00 套系：2）',
            value: '成长套餐'
          },
          {
            label: ' 测试套A1 ',
            sublabel: ' （价格：26997.00 套系：3）',
            value: ' 测试套A1 '
          },
          {
            label: ' 123123 ',
            sublabel: ' （价格：0.00 套系：0）',
            value: ' 123123 '
          },
          {
            label: ' 测试--111 ',
            sublabel: ' （价格：1998.00 套系：2）',
            value: ' 测试--111 '
          },
          {
            label: ' 儿童乐高套餐 ',
            sublabel: ' （价格：2000.00 套系：2）',
            value: ' 儿童乐高套餐 '
          },
          {
            label: ' 成长2999 ',
            sublabel: ' （价格：2000.00 套系：2）',
            value: ' 成长2999 '
          },
          {
            label: ' chengzhang ',
            sublabel: ' （价格：1000.00 套系：3）',
            value: ' chengzhang '
          },
          {
            label: ' 测试 ',
            sublabel: ' （价格：3000.00 套系：2）',
            value: ' 测试 '
          },
          {
            label: ' 成长套系 ',
            sublabel: ' （价格：5997.00 套系：3）',
            value: ' 成长套系 '
          },
          {
            label: ' 成 ',
            sublabel: ' （价格：1999.00 套系：3）',
            value: ' 成 '
          },
          {
            label: ' 儿童大餐N ',
            sublabel: ' （价格：6000.00 套系：3）',
            value: ' 儿童大餐N '
          },
        ],
      }
    },
    watch: {
      '$store.state.layout.app.rowData'(newValue, oldValue) {
        this.rowData = newValue
        console.log(this.rowData);
        for (let key in this.rowData) {
          if (this.rowData[key] == null || this.rowData[key] == "null") {
            this.rowData[key] = ""
          }
          if (this.rowData['kz_status_id'] == 5 || this.rowData['state_id'] == 1) {
            this.isOrder = true
          } else {
            this.isOrder = false
          }
        }
        this.$refs['invitationFormRef'].resetFields()
        for (let key in this.invitationForm.trackingData) {
          this.invitationForm.trackingData[key] = this.rowData[key]
        }
        for (let key in this.invitationForm.appointmentData) {
          this.invitationForm.appointmentData[key] = this.rowData[key]
        }
        for (let key in this.invitationForm.orderData) {
          this.invitationForm.orderData[key] = this.rowData[key]
          if (key == 'store_employee') {
            this.storeYG = this.rowData[key] ? this.rowData[key].split('/') : []
          }
        }
        for (let key in this.invitationForm.invalidData) {
          this.invitationForm.invalidData[key] = this.rowData[key]
        }
      }
    },
    created() {
      this.rowData = this.$store.state.layout.app.rowData
      if (this.rowData['kz_status_id'] == 5  || this.rowData['state_id'] == 1) {
        this.isOrder = true
      } else {
        this.isOrder = false
      }
      for (let key in this.invitationForm.trackingData) {
        this.invitationForm.trackingData[key] = this.rowData[key]
      }
      for (let key in this.invitationForm.appointmentData) {
        this.invitationForm.appointmentData[key] = this.rowData[key]
      }
      for (let key in this.invitationForm.orderData) {
        this.invitationForm.orderData[key] = this.rowData[key]
        if (key == 'store_employee') {
          this.storeYG = this.rowData[key] && this.rowData[key].split('/')
        }
      }
      for (let key in this.invitationForm.invalidData) {
        this.invitationForm.invalidData[key] = this.rowData[key]
      }
      this.storeEmployeeOptions = store_employee_options
      this.getStore()
    },
    methods: {
      // 获取所有店铺列表
      getStore() {
        getAllstore().then(res => {
          console.log('获取所有店铺列表', res);
          if (res.rstpCode === '0000') {
            this.storeList = res.data;
          } else {
            this.$Message.error(res.rstpMsg);
          }
        })
      },
      // 上传客资备注图片
      kzRemarksUpload(file) {
        console.log(file);
        const isLt2M = file.file.size / 1024 / 1024 < 2;
        if (!isLt2M) {
          this.loading = false;
          this.$message.error("上传图片大小不能超过 2MB!");
          return false;
        }
        const formData = new FormData();
        formData.append("image", file.file);
        upload_image(formData).then(res => {
          console.log('上传图片', res);
          if (res.rstpCode === '0000') {
            this.rowData.image_note = process.env.VUE_APP_BASE_SERVE + res.data[0].url
          }
        })
      },
      handlePictureCardExceed(files, fileList) {
        this.$Message.error('最多上传一张图片');
      },
      handlePictureCardPreview(file) {
        this.imgDialogVisible2 = true
      },
      handleRemove(file, fileList) {
        this.rowData.image_note = ''
      },
      // 跟踪确定
      trackingConfirm() {
        this.$refs['invitationFormRef'].validateField('trackingData.tracking_type', (errorMessage) => {
          if (!errorMessage) {
            this.invitationForm.trackingData.kz_id = this.rowData.kz_id
            this.invitationForm.trackingData.image_note = this.rowData.image_note
            this.invitationForm.trackingData.sub_kz_status_id = this.invitationForm.trackingData.tracking_type
            this.updatekezi(this.invitationForm.trackingData)
          }
        });
      },
      // 预约确定
      appointmentConfirm() {
        let fieldsToValidate = ['appointmentData.store_id', 'appointmentData.appointment_date',
          'appointmentData.appointment_time'
        ];
        let _self = this;
        Promise.all(fieldsToValidate.map(item => {
          let p = new Promise(function(resolve, reject) {
            _self.$refs['invitationFormRef'].validateField(item, (error) => {
              resolve(error)
            })
          });
          return p;
        })).then((data) => {
          console.info(data)
          // data 里是各个字段的验证错误信息, 如果为空串则认为验证通过, 如果数组里全为空串则所有验证通过
          // 判断data 里是否全是空串
          // 去除数组空值
          data = data.filter(item => item)
          if (!data.length) {
            console.log('通过验证')
            this.invitationForm.appointmentData.kz_id = this.rowData.kz_id
            this.invitationForm.appointmentData.sub_kz_status_id = '12'
            this.updatekezi(this.invitationForm.appointmentData)
          } else {
            console.log('验证不通过')
          }
        })
      },
      // 邀约订单确定
      orderConfirm() {
        this.$refs['invitationFormRef'].validateField('orderData.order_type', (errorMessage) => {
          console.log(errorMessage);
          if (!errorMessage) {
            this.invitationForm.orderData.kz_id = this.rowData.kz_id
            this.invitationForm.orderData.sub_kz_status_id = '15'
            this.isOrder = true
            this.updatekezi(this.invitationForm.orderData)
            const storeData = {
              ...this.rowData,
              ...this.invitationForm.orderData
            }
            addNewOrder(storeData).then(res => {
              console.log('新增订单', res);
              if (res.rstpCode === '0000') {
                this.$Message.success('新增订单成功');
                this.$emit('queryALlKz')
              } else {
                this.$Message.error({
                  message: res.rstpMsg,
                  duration: 0,
                  customClass: 'myMessageClass'
                });
              }
            })
          }
        });
      },
      // 无效流失确定
      invalidConfirm() {
        this.$refs['invitationFormRef'].validateField('invalidData.invalid_reason', (errorMessage) => {
          if (!errorMessage) {
            this.invitationForm.invalidData.kz_id = this.rowData.kz_id
            this.invitationForm.invalidData.image_note = this.rowData.image_note
            this.updatekezi(this.invitationForm.invalidData)
          }
        });
      },
      // 跟新客资
      updatekezi(data) {
        updateKz(data).then(res => {
          console.log('保存编辑内容', res);
          if (res.rstpCode === '0000') {
            this.$Message.success('修改成功');
            this.$emit('queryALlKz')
          } else {
            this.$Message.error({
              message: res.rstpMsg,
              duration: 0,
              customClass: 'myMessageClass'
            });
          }
        })
      },
      // 选择下次跟踪时间
      next_tracking_time_change(val, date) {
        console.log(val);
        this.invitationForm.trackingData.next_tracking_time = val
      },
      // 选择邀约订单时间
      order_time_change(val, date) {
        console.log(val);
        this.invitationForm.orderData.order_time = val
      },
      // 选择邀约订单婚期
      wedding_date_change(val, date) {
        console.log(val);
        this.invitationForm.orderData.wedding_date = val
      },
      // 选择预约到店日期
      appointment_date_change(val, date) {
        console.log(val);
        this.invitationForm.appointmentData.appointment_date = val
      },
      // 选择门店事件
      storeChange(e) {
        console.log(e);
        this.invitationForm.appointmentData.store_id = e
        this.invitationForm.appointmentData.store_name = this.storeList.find(item => item.store_id == e).store_name
      },
      reservationChange(value) {
        console.log(value);
        this.invitationForm.appointment_time = value
      },
      // 门店员工选择
      storeEmployeeChange(value, selectedData) {
        console.log(value, selectedData);
        this.invitationForm.orderData.store_employee = value.join('/')
      }
    },
  }
</script>

<style scoped lang="less">
</style>
